/**
 * Created by pan on 2017/6/22.
 */

var express = require("express");
var router = express.Router();
var superagent = require("superagent");

router.get("/", function(req, res, next){
    superagent
    .get(`http://b.zhuishushenqi.com/books/auto-suggest?query=${encodeURIComponent(req.query.text)}&packageName=com.ifmoc.ZhuiShuShenQi`)
    .end(function(err, response){
        if(err) {
            res.send({
                result: 0,
                msg: err
            });
        } else {
            try {
                res.send({
                    result: 1,
                    data: JSON.parse(response.text)
                });
            } catch(e) {
                res.send({
                    result: 0,
                    msg: e.toString()
                });
            }
        }
    });
});

module.exports = router;
